package com.dingwei.superiordiary.ui.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bobomee.android.mentions.edit.MentionEditText;
import com.bobomee.android.mentions.edit.util.FormatRangeManager;
import com.bobomee.android.mentions.text.MentionTextView;
import com.bumptech.glide.Glide;
import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.adapter.adapter.FindDetailsEvaluationListAdapter;
import com.dingwei.superiordiary.adapter.adapter.FindDetailsPicAdapter;
import com.dingwei.superiordiary.app.MyApplication;
import com.dingwei.superiordiary.bean.CommentBean;
import com.dingwei.superiordiary.bean.CommentSuccessBean;
import com.dingwei.superiordiary.bean.MyCarePersonalBean;
import com.dingwei.superiordiary.bean.PostDetailsBean;
import com.dingwei.superiordiary.mvp.presenter.FindDetailsPresenter;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.dingwei.superiordiary.parser.Parser;
import com.dingwei.superiordiary.utils.ShareDialogUtils;
import com.dingwei.superiordiary.utils.SpannableStringUtils;
import com.dingwei.superiordiary.weight.SampleCoverVideo1;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.jude.easyrecyclerview.decoration.DividerDecoration;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.ColumValue;
import com.lihao.baselibrary.utils.KeyboardUtils;
import com.lihao.baselibrary.utils.L;
import com.lihao.baselibrary.utils.NetWorkUtil;
import com.lihao.baselibrary.weight.MyGridView;
import com.lihao.baselibrary.weight.TitleBar;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadmoreListener;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.shuyu.gsyvideoplayer.video.base.GSYVideoPlayer;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.utils.SocializeUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created time 2018/1/24.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class FindDetailsActivity extends BaseActivity implements Contract.FindDetailsView {

    FindDetailsPresenter findDetailsPresenter = new FindDetailsPresenter(this);
    ImageView imageView;
    @Bind(R.id.main_titleBar)
    TitleBar mainTitleBar;
    @Bind(R.id.ll_bottom)
    LinearLayout llBottom;
    @Bind(R.id.img_head)
    ImageView imgHead;
    @Bind(R.id.tv_nick_name)
    TextView tvNickName;
    @Bind(R.id.tv_level)
    TextView tvLevel;
    @Bind(R.id.tv_signature)
    TextView tvSignature;
    @Bind(R.id.tv_add_time)
    TextView tvAddTime;
    @Bind(R.id.tv_posts_type)
    TextView tvPostsType;
    @Bind(R.id.tv_title)
    MentionTextView tvTitle;
    @Bind(R.id.video_item_player)
    SampleCoverVideo1 videoItemPlayer;
    @Bind(R.id.gridview)
    MyGridView gridview;
    @Bind(R.id.tv_forward_num)
    TextView tvForwardNum;
    @Bind(R.id.tv_evaluation_num)
    TextView tvEvaluationNum;
    @Bind(R.id.img_like)
    ImageView imgLike;
    @Bind(R.id.tv_like_num)
    TextView tvLikeNum;
    @Bind(R.id.like_layout)
    LinearLayout likeLayout;
    @Bind(R.id.ic_tread)
    ImageView icTread;
    @Bind(R.id.tv_tread_num)
    TextView tvTreadNum;
    @Bind(R.id.tread_layout)
    LinearLayout treadLayout;
    @Bind(R.id.tv_sort)
    TextView tvSort;
    @Bind(R.id.m_recyclerView)
    RecyclerView mRecyclerView;
    @Bind(R.id.refresh_layout)
    SmartRefreshLayout refreshLayout;
    @Bind(R.id.tv_choose_num)
    TextView tvChooseNum;
    @Bind(R.id.tv_cancel_choose)
    TextView tvCancelChoose;
    @Bind(R.id.choose_pic_layout)
    LinearLayout choosePicLayout;
    @Bind(R.id.data_layout)
    RelativeLayout dataLayout;
    @Bind(R.id.no_net_btn)
    TextView noNetBtn;
    @Bind(R.id.no_net_layout)
    RelativeLayout noNetLayout;
    @Bind(R.id.img_choose_pic)
    ImageView imgChoosePic;
    @Bind(R.id.et_comment)
    MentionEditText etComment;
    @Bind(R.id.btn_submit)
    Button btnSubmit;
    @Bind(R.id.tv_forward_content)
    MentionTextView tvForwardContent;
    @Bind(R.id.forward_layout)
    LinearLayout forwardLayout;
    @Bind(R.id.header_layout)
    LinearLayout headerLayout;
    @Bind(R.id.tv_attention)
    TextView tvAttention;
    private FindDetailsEvaluationListAdapter mAdapter;
    private PostDetailsBean bean;
    private String id;
    private int page = 1;
    private int type = 2;
    private FormatRangeManager mRangeManager;
    private Parser mTagParser = new Parser();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        GSYVideoManager.onResume();
        findDetailsPresenter.initData(id);
        page = 1;
        findDetailsPresenter.getCommentList(id, page, type, true, true);
    }

    @Override
    protected void onPause() {
        super.onPause();
        GSYVideoManager.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        GSYVideoPlayer.releaseAllVideos();
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_find_details;
    }

    @Override
    protected void initData() {
        findDetailsPresenter.initData(id);
        findDetailsPresenter.getCommentList(id, 1, type, true, true);
    }

    @Override
    protected void initView() {
        mRangeManager = new FormatRangeManager();
        tvTitle.setMovementMethod(new LinkMovementMethod());
        tvTitle.setParserConverter(mTagParser);
        tvTitle.setHighlightColor(getResources().getColor(android.R.color.transparent));
        tvForwardContent.setMovementMethod(new LinkMovementMethod());
        tvForwardContent.setParserConverter(mTagParser);
        tvForwardContent.setHighlightColor(getResources().getColor(android.R.color.transparent));
        if (getIntent().getScheme() != null) {
            Intent intent1 = getIntent();
            Uri uri = intent1.getData();
            Log.e("test", "scheme: " + uri.getScheme());
            Log.e("test", "host: " + uri.getHost());
            Log.e("test", "port: " + uri.getPort());
            Log.e("test", "path: " + uri.getPath());
            Log.e("test", "queryString: " + uri.getQuery());
            Log.e("test", "queryParameter: " + uri.getQueryParameter("id"));
            id = uri.getQueryParameter("id");
        } else {
            id = getIntent().getStringExtra("id");
        }
        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setNestedScrollingEnabled(false);
        mAdapter = new FindDetailsEvaluationListAdapter(BaseActivity.context);
        mRecyclerView.addItemDecoration(new DividerDecoration(getResources().getColor(R.color.line), 1));
        mRecyclerView.setAdapter(mAdapter);


        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent();
                intent.setClass(context, PhotoDetailsActivity.class);
                intent.putExtra("position", i);
                intent.putExtra("img", (Serializable) bean.data.detail.image);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void initListener() {
        refreshLayout.setOnRefreshLoadmoreListener(new OnRefreshLoadmoreListener() {
            @Override
            public void onLoadmore(RefreshLayout refreshlayout) {
                page = page + 1;
                findDetailsPresenter.getCommentList(id, page, type, false, false);
            }

            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                page = 1;
                findDetailsPresenter.getCommentList(id, page, type, true, false);
            }
        });

        mAdapter.setReplyInterface(new FindDetailsEvaluationListAdapter.ReplyInterface() {

            @Override
            public void likes(int position) {
                CommentBean.DataBean.ListBean bean = mAdapter.getItem(position);
                findDetailsPresenter.commentLike(bean.id, position, -1);
            }

            @Override
            public void Sublikes(int dataPosition, int position) {
                CommentBean.DataBean.ListBean.SubBean bean = mAdapter.getItem(dataPosition).sub.get(position);
                findDetailsPresenter.commentLike(bean.id, dataPosition, position);
            }

            @Override
            public void cai(int position) {
                CommentBean.DataBean.ListBean bean = mAdapter.getItem(position);
                findDetailsPresenter.commentCai(bean.id, position);
            }

            @Override
            public void subUser(String user_id) {
                intent = new Intent(BaseActivity.context, LookUserCenterActivity.class);
                intent.putExtra("user_id", user_id);
                startActivity(intent);
            }

            @Override
            public void more(int position) {
                CommentBean.DataBean.ListBean bean = mAdapter.getItem(position);
                intent = new Intent(BaseActivity.context, MoreReplyActivity.class);
                intent.putExtra("id", bean.id);
                startActivity(intent);


            }
        });

        mAdapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int i) {
                CommentBean.DataBean.ListBean bean = mAdapter.getItem(i);
                intent = new Intent(BaseActivity.context, MoreReplyActivity.class);
                intent.putExtra("id", bean.id);
                startActivity(intent);
            }
        });
        mainTitleBar.setOnMenuListener(new TitleBar.OnMenuListener() {
            @Override
            public void onMenuClick() {
                findDetailsPresenter.showMeunPopupWindow(mainTitleBar.getMenu(), bean.data.detail.is_collect);
            }
        });

        etComment.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (count == 1 && !TextUtils.isEmpty(s)) {
                    char mentionChar = s.toString().charAt(start);
                    int selectionStart = etComment.getSelectionStart();
                    if (mentionChar == '@') {
                        intent = new Intent(BaseActivity.context, aitePersonalActivity.class);
                        intent.putExtra("userid", BaseActivity.value.getUserId());
                        startActivityForResult(intent, 1001);
                        etComment.getText().delete(selectionStart - 1, selectionStart);
                    }
                }
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });
    }


    @Override
    public void share() {
        ShareDialogUtils.showShareDialog(this, bean.data.detail.share_data.url, bean.data.detail.share_data.title, bean.data.detail.share_data.img, bean.data.detail.share_data.desc, "11", shareListener);
    }

    @Override
    public void report() {
        intent = new Intent(context, ReportActivity.class);
        intent.putExtra("id", id);
        intent.putExtra("tip_type", "tie");
        startActivity(intent);
    }

    @Override
    public void collectSuccess() {
        if (bean.data.detail.is_collect == 1) {
            bean.data.detail.is_collect = 0;
        } else {
            bean.data.detail.is_collect = 1;
        }
    }


    @Override
    public void SetHotSort() {
        tvSort.setText("热门");
        page = 1;
        type = 3;
        findDetailsPresenter.getCommentList(id, page, type, true, true);
    }

    @Override
    public void SetZhengSort() {
        tvSort.setText("正序");
        page = 1;
        type = 2;
        findDetailsPresenter.getCommentList(id, page, type, true, true);
    }

    @Override
    public void SetDaoSort() {
        tvSort.setText("倒序");
        page = 1;
        type = 1;
        findDetailsPresenter.getCommentList(id, page, type, true, true);
    }


    @Override
    public void Fail() {
        showData("fail");
    }

    OrientationUtils orientationUtils;

    @Override
    public void setData(final PostDetailsBean bean) {
        showData("success");

        this.bean = bean;

        if (bean.data.detail.istranspond == 0) {
            Glide.with(BaseActivity.context)
                    .load(bean.data.detail.portrait)
                    .apply(MyApplication.headOptions)
                    .into(imgHead);
            tvNickName.setText(bean.data.detail.nickname);
            tvAddTime.setText(bean.data.detail.addtime);
            tvLevel.setText("LV." + bean.data.detail.level);
            tvSignature.setText(bean.data.detail.idiograph);
            String s = bean.data.detail.content.replaceAll("'>", "'>@");
            tvTitle.setText(mRangeManager.getFormatCharSequence(s));

            if (bean.data.detail.source.equals("0")) {
                tvPostsType.setVisibility(View.VISIBLE);
                if (bean.data.detail.type == 0) {
                    tvPostsType.setText(" 综合 ");
                } else {
                    tvPostsType.setText("个人说");
                }
            } else {
                tvPostsType.setVisibility(View.GONE);
                tvTitle.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        intent = new Intent(BaseActivity.context, WebViewActivity.class);
                        intent.putExtra("title", "详情");
                        intent.putExtra("url", bean.data.detail.url);
                        startActivity(intent);
                    }
                });
                headerLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        intent = new Intent(BaseActivity.context, WebViewActivity.class);
                        intent.putExtra("title", "详情");
                        intent.putExtra("url", bean.data.detail.url);
                        startActivity(intent);
                    }
                });
            }


            tvForwardNum.setText(bean.data.detail.transpond);
            tvEvaluationNum.setText(bean.data.detail.comments);

            tvLikeNum.setText(bean.data.detail.likes);
            tvTreadNum.setText(bean.data.detail.trample);

            if (bean.data.detail.is_liked == 1) {
                imgLike.setImageResource(R.mipmap.ic_liked);
            } else {
                imgLike.setImageResource(R.mipmap.ic_like);
            }

            if (BaseActivity.value.getUserId().equals(bean.data.detail.consumer_id)) {
                tvAttention.setVisibility(View.GONE);
            } else {
                tvAttention.setVisibility(View.VISIBLE);
                if (bean.data.detail.attentioned==0) {
                    tvAttention.setText("+关注");
                    tvAttention.setTextColor(ContextCompat.getColor(BaseActivity.context, R.color.theme_color));
                    tvAttention.setBackgroundResource(R.drawable.theme_line_bg);
                } else {
                    tvAttention.setText("已关注");
                    tvAttention.setTextColor(ContextCompat.getColor(BaseActivity.context, R.color.white));
                    tvAttention.setBackgroundResource(R.drawable.theme_bg);
                }
            }

            if (TextUtils.isEmpty(bean.data.detail.video)) {
                videoItemPlayer.setVisibility(View.GONE);
                gridview.setVisibility(View.VISIBLE);
                FindDetailsPicAdapter adapter = new FindDetailsPicAdapter(BaseActivity.context, bean.data.detail.image);
                gridview.setAdapter(adapter);
            } else {
                videoItemPlayer.setVisibility(View.VISIBLE);
                gridview.setVisibility(View.GONE);
                videoItemPlayer.setEnlargeImageRes(R.drawable.jz_enlarge);
                videoItemPlayer.setShrinkImageRes(R.drawable.jz_shrink);
                videoItemPlayer.setUp(bean.data.detail.video, false, "");
                imageView = new ImageView(BaseActivity.context);
                //增加封面
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                Glide.with(BaseActivity.context)
                        .load(bean.data.detail.video_image)
                        .into(imageView);
                videoItemPlayer.setThumbImageView(imageView);
                videoItemPlayer.getTitleTextView().setVisibility(View.GONE);
                videoItemPlayer.setBottomProgressBarDrawable(BaseActivity.context.getResources().getDrawable(R.drawable.video_new_progress));
                videoItemPlayer.setBottomShowProgressBarDrawable(BaseActivity.context.getResources().getDrawable(R.drawable.video_new_seekbar_progress), BaseActivity.context.getResources().getDrawable(R.drawable.video_new_seekbar_thumb));

                //设置返回键
                videoItemPlayer.getBackButton().setVisibility(View.GONE);
                //设置旋转
                orientationUtils = new OrientationUtils(this, videoItemPlayer);
                //设置全屏按键功能,这是使用的是选择屏幕，而不是全屏
                videoItemPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        resolveFullBtn(videoItemPlayer);
                    }
                });

                autoPlay();
            }

            forwardLayout.setBackgroundResource(R.color.white);
            tvForwardContent.setVisibility(View.GONE);
        } else {
            forwardLayout.setBackgroundResource(R.color.bg);
            forwardLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (bean.data.detail.source.equals("0")) {
                        intent = new Intent(BaseActivity.context, FindDetailsActivity.class);
                        intent.putExtra("id", bean.data.detail.transpond_content.id);
                        startActivity(intent);
                    } else {
                        intent = new Intent(BaseActivity.context, WebViewActivity.class);
                        intent.putExtra("title", "详情");
                        intent.putExtra("url", bean.data.detail.url);
                        startActivity(intent);
                    }

                }
            });
            tvForwardContent.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (bean.data.detail.source.equals("0")) {
                        intent = new Intent(BaseActivity.context, FindDetailsActivity.class);
                        intent.putExtra("id", bean.data.detail.transpond_content.id);
                        startActivity(intent);
                    } else {
                        intent = new Intent(BaseActivity.context, WebViewActivity.class);
                        intent.putExtra("title", "详情");
                        intent.putExtra("url", bean.data.detail.url);
                        startActivity(intent);
                    }
                }
            });
            tvForwardContent.setVisibility(View.VISIBLE);
            String s = bean.data.detail.transpond_content.content.replaceAll("'>", "'>@");
            s = " <user id='" + bean.data.detail.transpond_content.consumer_id + "' name='" + bean.data.detail.transpond_content.nickname + "'>@" + bean.data.detail.transpond_content.nickname + "</user> " + s;
            tvForwardContent.setText(s);
            Glide.with(BaseActivity.context)
                    .load(bean.data.detail.portrait)
                    .apply(MyApplication.headOptions)
                    .into(imgHead);
            tvNickName.setText(bean.data.detail.nickname);
            tvAddTime.setText(bean.data.detail.addtime);
            tvLevel.setText("LV." + bean.data.detail.level);
            tvSignature.setText(bean.data.detail.idiograph);
            String s1 = bean.data.detail.content.replaceAll("'>", "'>@");
            tvTitle.setText(mRangeManager.getFormatCharSequence(s1));

            if (bean.data.detail.type == 0) {
                tvPostsType.setText(" 综合 ");
            } else {
                tvPostsType.setText("个人说");
            }

            tvForwardNum.setText(bean.data.detail.transpond);
            tvEvaluationNum.setText(bean.data.detail.comments);

            tvLikeNum.setText(bean.data.detail.likes);
            tvTreadNum.setText(bean.data.detail.trample);

            if (bean.data.detail.is_liked == 1) {
                imgLike.setImageResource(R.mipmap.ic_liked);
            } else {
                imgLike.setImageResource(R.mipmap.ic_like);
            }

            if (BaseActivity.value.getUserId().equals(bean.data.detail.consumer_id)) {
                tvAttention.setVisibility(View.GONE);
            } else {
                tvAttention.setVisibility(View.VISIBLE);
                if (bean.data.detail.attentioned==0) {
                    tvAttention.setText("+关注");
                    tvAttention.setTextColor(ContextCompat.getColor(BaseActivity.context, R.color.theme_color));
                    tvAttention.setBackgroundResource(R.drawable.theme_line_bg);
                } else {
                    tvAttention.setText("已关注");
                    tvAttention.setTextColor(ContextCompat.getColor(BaseActivity.context, R.color.white));
                    tvAttention.setBackgroundResource(R.drawable.theme_bg);
                }
            }

            if (TextUtils.isEmpty(bean.data.detail.video)) {
                videoItemPlayer.setVisibility(View.GONE);
                gridview.setVisibility(View.VISIBLE);
                FindDetailsPicAdapter adapter = new FindDetailsPicAdapter(BaseActivity.context, bean.data.detail.image);
                gridview.setAdapter(adapter);
            } else {
                videoItemPlayer.setVisibility(View.VISIBLE);
                gridview.setVisibility(View.GONE);
                videoItemPlayer.setEnlargeImageRes(R.drawable.jz_enlarge);
                videoItemPlayer.setShrinkImageRes(R.drawable.jz_shrink);
                videoItemPlayer.setUp(bean.data.detail.video, false, "");
                imageView = new ImageView(BaseActivity.context);
                //增加封面
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                Glide.with(BaseActivity.context)
                        .load(bean.data.detail.video_image)
                        .into(imageView);
                videoItemPlayer.setThumbImageView(imageView);
                videoItemPlayer.getTitleTextView().setVisibility(View.GONE);
                videoItemPlayer.setBottomProgressBarDrawable(BaseActivity.context.getResources().getDrawable(R.drawable.video_new_progress));
                videoItemPlayer.setBottomShowProgressBarDrawable(BaseActivity.context.getResources().getDrawable(R.drawable.video_new_seekbar_progress), BaseActivity.context.getResources().getDrawable(R.drawable.video_new_seekbar_thumb));

                //设置返回键
                videoItemPlayer.getBackButton().setVisibility(View.GONE);
                //设置旋转
                orientationUtils = new OrientationUtils(this, videoItemPlayer);
                //设置全屏按键功能,这是使用的是选择屏幕，而不是全屏
                videoItemPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        resolveFullBtn(videoItemPlayer);
                    }
                });

                autoPlay();
            }
        }


    }

    public void autoPlay() {
        if (BaseActivity.value.getAutoPlayVideo() == ColumValue.WIFI) {
            if (NetWorkUtil.getNetWorkType(BaseActivity.context) == NetWorkUtil.NETWORKTYPE_WIFI) {
                videoItemPlayer.setNeedShowWifiTip(false);
                videoItemPlayer.startPlayLogic();
            } else {
                videoItemPlayer.setNeedShowWifiTip(true);
            }
        } else if (BaseActivity.value.getAutoPlayVideo() == ColumValue.NETWORK) {
            if (NetWorkUtil.getNetWorkType(BaseActivity.context) == NetWorkUtil.NETWORKTYPE_WIFI || NetWorkUtil.getNetWorkType(BaseActivity.context) == NetWorkUtil.NETWORKTYPE_3G || NetWorkUtil.getNetWorkType(BaseActivity.context) == NetWorkUtil.NETWORKTYPE_2G || NetWorkUtil.getNetWorkType(BaseActivity.context) == NetWorkUtil.NETWORKTYPE_WAP) {
                videoItemPlayer.setNeedShowWifiTip(false);
                videoItemPlayer.startPlayLogic();
            } else {
                videoItemPlayer.setNeedShowWifiTip(true);
            }
        } else if (BaseActivity.value.getAutoPlayVideo() == ColumValue.NO) {
            videoItemPlayer.setNeedShowWifiTip(true);
        }
    }

    @Override
    public void OnRefresh(boolean isRefresh, CommentBean bean) {
        refreshLayout.finishRefresh();
        mAdapter.clear();
        mAdapter.addAll(bean.data.list);
    }

    @Override
    public void OnLoadMore(boolean isRefresh, CommentBean bean) {
        refreshLayout.finishLoadmore();
        mAdapter.addAll(bean.data.list);
    }

    @Override
    public void commentLikeSuccess(int dataPosition, int position) {

        if (position == -1) {
            CommentBean.DataBean.ListBean bean = mAdapter.getItem(dataPosition);
            if (bean.is_liked == 0) {
                bean.is_liked = 1;
                bean.likes = (Integer.parseInt(bean.likes) + 1) + "";
            } else {
                bean.is_liked = 0;
                bean.likes = (Integer.parseInt(bean.likes) - 1) + "";
            }
            mAdapter.notifyDataSetChanged();
        } else {
            CommentBean.DataBean.ListBean.SubBean bean = mAdapter.getItem(dataPosition).sub.get(position);
            if (bean.is_liked == 0) {
                bean.is_liked = 1;
                bean.likes = (Integer.parseInt(bean.likes) + 1) + "";
            } else {
                bean.is_liked = 0;
                bean.likes = (Integer.parseInt(bean.likes) - 1) + "";
            }
            mAdapter.notifyDataSetChanged();
        }


    }

    @Override
    public void LikeSuccess() {
        if (bean.data.detail.is_liked == 1) {
            bean.data.detail.is_liked = 0;
            imgLike.setImageResource(R.mipmap.ic_like);
            bean.data.detail.likes = (Integer.parseInt(bean.data.detail.likes) - 1) + "";
            tvLikeNum.setText(bean.data.detail.likes);
        } else {
            bean.data.detail.is_liked = 1;
            imgLike.setImageResource(R.mipmap.ic_liked);
            bean.data.detail.likes = (Integer.parseInt(bean.data.detail.likes) + 1) + "";
            tvLikeNum.setText(bean.data.detail.likes);
        }
    }

    @Override
    public void commentSuccess(CommentSuccessBean bean) {

        L.e("-------2--");
        this.bean.data.detail.comments = (Integer.parseInt(this.bean.data.detail.comments) + 1) + "";
        tvEvaluationNum.setText(this.bean.data.detail.comments);

        page = 1;
        findDetailsPresenter.getCommentList(id, page, type, true, true);
        L.e("-------3--");
        etComment.setText("");
        photoList.clear();
        choosePicLayout.setVisibility(View.GONE);

    }

    @Override
    public void TrampleSuccess() {
        tvTreadNum.setText("" + (Integer.parseInt(bean.data.detail.trample) + 1));
    }

    @Override
    public void trampleCommentSuccess(int position) {
        CommentBean.DataBean.ListBean bean = mAdapter.getItem(position);
        bean.trample = (Integer.parseInt(bean.likes) + 1) + "";
        mAdapter.notifyItemChanged(position, bean);

    }

    @Override
    public void attentionActionSuccess() {
        bean.data.detail.attentioned = bean.data.detail.attentioned == 0 ? 1 : 0;
        if (bean.data.detail.attentioned==0) {
            tvAttention.setText("+关注");
            tvAttention.setTextColor(ContextCompat.getColor(BaseActivity.context, R.color.theme_color));
            tvAttention.setBackgroundResource(R.drawable.theme_line_bg);
        } else {
            tvAttention.setText("已关注");
            tvAttention.setTextColor(ContextCompat.getColor(BaseActivity.context, R.color.white));
            tvAttention.setBackgroundResource(R.drawable.theme_bg);
        }
    }

    @Override
    public void collect() {
        findDetailsPresenter.activityCollect(id, bean.data.detail.is_collect);
    }

    public void showData(String state) {
        if (state.equals("success")) {
            dataLayout.setVisibility(View.VISIBLE);
            noNetLayout.setVisibility(View.GONE);
        } else {
            dataLayout.setVisibility(View.GONE);
            noNetLayout.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onBackPressed() {
        if (StandardGSYVideoPlayer.backFromWindowFull(this)) {
            return;
        }
        super.onBackPressed();
    }

    /**
     * 全屏幕按键处理
     */
    private void resolveFullBtn(final StandardGSYVideoPlayer standardGSYVideoPlayer) {
        standardGSYVideoPlayer.startWindowFullscreen(context, true, true);
    }


    private UMShareListener shareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA platform) {
            SocializeUtils.safeShowDialog(dialog);
        }

        @Override
        public void onResult(SHARE_MEDIA platform) {
            Toast.makeText(FindDetailsActivity.this, "分享成功", Toast.LENGTH_LONG).show();
            SocializeUtils.safeCloseDialog(dialog);
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            SocializeUtils.safeCloseDialog(dialog);
            Toast.makeText(FindDetailsActivity.this, "分享失败" + t.getMessage(), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
            SocializeUtils.safeCloseDialog(dialog);
            Toast.makeText(FindDetailsActivity.this, "取消分享", Toast.LENGTH_LONG).show();

        }
    };
    private List<LocalMedia> photoList = new ArrayList<>();

    @OnClick({R.id.img_choose_pic, R.id.img_head, R.id.tv_attention, R.id.like_layout, R.id.tv_sort, R.id.tread_layout, R.id.tv_cancel_choose, R.id.no_net_btn, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_choose_pic:
                PictureSelector.create(FindDetailsActivity.this)
                        .openGallery(PictureMimeType.ofImage())
                        .theme(R.style.picture_white_style)
                        .imageSpanCount(3)
                        .maxSelectNum(3)
                        .selectionMode(PictureConfig.MULTIPLE)
                        .previewImage(true)
                        .isCamera(true)
                        .isZoomAnim(true)
                        .selectionMedia(photoList)
                        .enableCrop(false)// 是否裁剪 true or false
                        .compress(true)// 是否压缩 true or false
                        .previewEggs(true) // 预览图片时 是否增强左右滑动图片体验(图片滑动一半即可看到上一张是否选中) true or false
                        .minimumCompressSize(100) // 小于100kb的图片不压缩
                        .forResult(PictureConfig.CHOOSE_REQUEST);
                break;
            case R.id.img_head:
                intent = new Intent(BaseActivity.context, LookUserCenterActivity.class);
                intent.putExtra("user_id", bean.data.detail.consumer_id);
                startActivity(intent);
                break;
            case R.id.tv_attention:
                if (bean.data.detail.attentioned == 0) {
                    findDetailsPresenter.attentionAction(bean.data.detail.consumer_id, "1");
                } else {
                    findDetailsPresenter.attentionAction(bean.data.detail.consumer_id, "0");
                }
                break;
            case R.id.tv_sort:
                findDetailsPresenter.showSortPopupWindow(tvSort);
                break;
            case R.id.like_layout:
                findDetailsPresenter.like(id);
                break;
            case R.id.tread_layout:
                findDetailsPresenter.cai(id);
                break;
            case R.id.tv_cancel_choose:
                photoList.clear();
                choosePicLayout.setVisibility(View.GONE);
                break;
            case R.id.no_net_btn:
                findDetailsPresenter.initData(id);
                page = 1;
                findDetailsPresenter.getCommentList(id, page, type, true, true);
                break;
            case R.id.btn_submit:
                CharSequence convertMetionString = etComment.getFormatCharSequence();
                findDetailsPresenter.saveComment(id, convertMetionString.toString(), photoList);
                KeyboardUtils.hideSoftInput(this);
                break;
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            return;
        }
        if (requestCode == PictureConfig.CHOOSE_REQUEST) {
            if (data != null) {
                List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                photoList.clear();
                for (LocalMedia localMedia : selectList) {
                    if (!TextUtils.isEmpty(localMedia.getCompressPath())) {
                        photoList.add(localMedia);
                    }
                }
                if (photoList.size() == 10) {
                    photoList.remove(photoList.size() - 1);
                }

                if (photoList != null && photoList.size() > 0) {
                    choosePicLayout.setVisibility(View.VISIBLE);
                    tvChooseNum.setText(SpannableStringUtils.getBuilder("已选择")
                            .append("" + photoList.size()).setForegroundColor(ContextCompat.getColor(BaseActivity.context, R.color.theme_color))
                            .append("张图片").create());
                } else {
                    choosePicLayout.setVisibility(View.GONE);
                }

            }
        }
        if (requestCode == 1001) {
            MyCarePersonalBean.DataBean.ListBean user = (MyCarePersonalBean.DataBean.ListBean) data.getSerializableExtra("user");
            etComment.insert(user);
        }
    }
}
